import config


class RegisterLoginAPI:

    # 1、获取图⽚验证码接口
    @classmethod
    def get_image_code(cls, session, r):
        url = config.Host + f"/common/public/verifycode1/{r}"
        resp = session.get(url)
        return resp

    # 2、获取短信验证码接口
    @classmethod
    def get_phone_code(cls, session, phone, imgVerifyCode):
        url = config.Host + "/member/public/sendSms"
        header = {"Content-Type": "application/x-www-form-urlencoded"}
        body = {"phone": phone, "imgVerifyCode": imgVerifyCode, "type": "reg"}
        resp = session.post(url=url, headers=header, data=body)
        return resp

    # 3、注册接口
    @classmethod
    def register(cls, session, phone, password, verifycode, phone_code):
        url = config.Host + "/member/public/reg"
        header = {"Content-Type": "application/x-www-form-urlencoded"}
        body = {"phone": phone, "password": password, "verifycode": verifycode, "phone_code": phone_code,
                "dy_server": "on", "invite_phone": ""}
        resp = session.post(url=url, headers=header, data=body)
        return resp

    # 4、登录接口
    @classmethod
    def login(cls, session, keywords, password):
        url = config.Host + "/member/public/login"
        header = {"Content-Type": "application/x-www-form-urlencoded"}
        body = {"keywords": keywords, "password": password}
        resp = session.post(url=url, headers=header, data=body)
        return resp

    # 5、 查询登录状态接口
    @classmethod
    def query_login_status(cls, session):
        url = config.Host + "/member/public/islogin"
        resp = session.post(url=url)
        return resp

    pass
